package com.ccsu.joysport.controller;

import com.ccsu.joysport.entity.Info;
import com.ccsu.joysport.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/ccsu")
public class getInfoController {
    @Autowired
    private InfoService infoService;
//收到资讯编号 返回资讯标题、图片、地址
    @GetMapping("/getInfo")
    public ResponseEntity<Map<String, String>> getInfo(@RequestParam Long infoID) {
        Info info = infoService.getInfoById(infoID);
        if (info != null) {
            Map<String, String> response = new HashMap<>();
            response.put("url", info.getUrl());
            response.put("imageUrl", info.getImageUrl());
            response.put("title", info.getTitle());
            response.put("description", info.getDescription());
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.status(404).body(null);
        }
    }
}
